package pl.edu.agh.iosr.gamblingzone.model;

import java.util.Date;

import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;


/**
 * The Class MoneyVoucher.
 */
@AttributeOverride(name="id",
		column=@Column(name="VOUCHER_ID"))
		@Entity(name="VOUCHERS")
		@Inheritance(strategy = InheritanceType.JOINED)
		public class MoneyVoucher extends EntityModel {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

	/** The expiration date. */
	@Column(name="VOUCHER_EXPIRATION_DATE", nullable=false)
	private Date expirationDate = null;

	/** The voucher hash. */
	@Column(name="VOUCHER_HASH", nullable=false)
	private String voucherHash = null;

	/** The value. */
	@Column(name="VOUCHER_VALUE", nullable=false)
	private Long value = 0L;

	/** The active. */
	@Column(name="VOUCHER_ISACTIVE", nullable=false)
	private boolean active = false;

	/** The owner. */
	@ManyToOne
	@JoinTable(name = "USER_VOUCHERS", 
			joinColumns = { @JoinColumn(name = "VOUCHER_ID") }, 
			inverseJoinColumns = { @JoinColumn(name = "USER_ID") })
			private User owner;

	/**
	 * Gets the expiration date.
	 * 
	 * @return the expiration date
	 */
	public Date getExpirationDate() {
		return expirationDate;
	}

	/**
	 * Sets the expiration date.
	 * 
	 * @param expirationDate the new expiration date
	 */
	public void setExpirationDate(Date expirationDate) {
		this.expirationDate = expirationDate;
	}

	/**
	 * Gets the voucher hash.
	 * 
	 * @return the voucher hash
	 */
	public String getVoucherHash() {
		return voucherHash;
	}

	/**
	 * Sets the voucher hash.
	 * 
	 * @param voucherHash the new voucher hash
	 */
	public void setVoucherHash(String voucherHash) {
		this.voucherHash = voucherHash;
	}

	/**
	 * Gets the value.
	 * 
	 * @return the value
	 */
	public Long getValue() {
		return value;
	}

	/**
	 * Sets the value.
	 * 
	 * @param value the new value
	 */
	public void setValue(Long value) {
		this.value = value;
	}

	/**
	 * Checks if is active.
	 * 
	 * @return true, if is active
	 */
	public boolean isActive() {
		return active;
	}

	/**
	 * Sets the active.
	 * 
	 * @param active the new active
	 */
	public void setActive(boolean active) {
		this.active = active;
	}

	/**
	 * Gets the owner.
	 * 
	 * @return the owner
	 */
	public User getOwner() {
		return owner;
	}

	/**
	 * Sets the owner.
	 * 
	 * @param owner the new owner
	 */
	protected void setOwner(User owner) {
		this.owner = owner;
	}
	
	// TODO equals hash
}
